package com.studyinghome.result;

/**
 * 自定义错误码
 *
 * @author leslie
 * @create 2018-11-05
 */
public class CodeMsg {

    private int code;
    private String msg;

    /**
     * 通用的错误码5001XX
     */
    public static CodeMsg SUCCESS = new CodeMsg(200, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500, "服务端异常");
    public static CodeMsg INSERT_ERROR = new CodeMsg(500, "添加数据失败");
    public static CodeMsg UPDATE_ERROR = new CodeMsg(500, "更新数据失败");
    public static CodeMsg REMOVE_ERROR = new CodeMsg(500, "删除数据失败");

    public static CodeMsg BIND_ERROR = new CodeMsg(400, "参数校验异常：请求参数不完整");
    public static CodeMsg DATA_TYPE_ERROR = new CodeMsg(400, "参数类型异常：请求参数类型错误");
    public static CodeMsg CHECK_UPDATE_ERROR = new CodeMsg(400, "参数校验错误：检查更新失败");
    public static CodeMsg REQUEST_METHOD_NOT_SUPPORTED = new CodeMsg(400, "请求提交方式不正确");

    public static CodeMsg DATA_NOT_EXIST = new CodeMsg(404, "数据不存在");
    public static CodeMsg COURSE_NOT_EXIST = new CodeMsg(404, "课程不存在");
    public static CodeMsg MUSICIAN_NOT_EXIST = new CodeMsg(404, "音乐家资源不存在");
    public static CodeMsg EXERCISE_NOT_EXIST = new CodeMsg(404, "课程练习不存在");
    public static CodeMsg MUSICAL_NOT_EXIST = new CodeMsg(404, "乐器不存在");
    public static CodeMsg KIND_MUSICAL_NOT_EXIST = new CodeMsg(404, "该种类乐器不存在");
    public static CodeMsg THEORY_NOT_EXIST = new CodeMsg(404, "乐理不存在");
    public static CodeMsg CHAPTER_NOT_EXIST = new CodeMsg(404, "乐理章节不存在");
    public static CodeMsg STAFF_NOT_EXIST = new CodeMsg(404, "曲谱不存在");
    public static CodeMsg MUSIC_NOT_EXIST = new CodeMsg(404, "音乐不存在");
    public static CodeMsg MUSIC_STYLE_NOT_EXIST = new CodeMsg(404, "该音乐种类中的资源尚未录入");
    public static CodeMsg COUNTRY_NOT_MUSICIAN = new CodeMsg(404, "该国籍音乐家资源尚未录入");
    public static CodeMsg MUSIC_STYLE_KIND_NOT_EXIST = new CodeMsg(404, "该音乐种类尚未录入");
    public static CodeMsg USER_NOT_EXIST = new CodeMsg(404, "用户不存在");
    public static CodeMsg NOT_TEACHER = new CodeMsg(404, "关联的教师账号不存在");
    public static CodeMsg USER_FORBIDDEN = new CodeMsg(403, "该用户账号已被禁用");
    public static CodeMsg TEACHER_FORBIDDEN = new CodeMsg(403, "教师账号已被禁用");
    public static CodeMsg VIDEO_NOT_EXIST = new CodeMsg(404, "暂无相关视频");
    public static CodeMsg UPLOAD_IS_NULL = new CodeMsg(400, "上传文件为空");
    public static CodeMsg FILE_TYPE_ERROR = new CodeMsg(400, "上传文件类型错误");
    public static CodeMsg UPLOAD_FILE_ERROR = new CodeMsg(400, "文件上传失败");

    /**
     * 用户模块5007XX
     */
    public static CodeMsg LOGIN_ERROR = new CodeMsg(500700, "用户名或密码错误");
    public static CodeMsg NAME_PWD_EMPTY = new CodeMsg(500701, "用户名或密码为空");
    public static CodeMsg REGISTER_ERROR = new CodeMsg(500702, "注册失败");
    public static CodeMsg SESSION_INVALID = new CodeMsg(500703, "登录信息失效或账号已在其它设备登录");
    public static CodeMsg USER_CHECK = new CodeMsg(500704, "用户信息审核中");
    public static CodeMsg USER_NOT_LOGIN = new CodeMsg(500705, "用户尚未登录");
    public static CodeMsg QUIT_ERROR = new CodeMsg(500706, "退出失败");
    public static CodeMsg STUDENT_EXIST = new CodeMsg(500707, "学生账号已存在，请不要重复添加");


    private CodeMsg() {
    }


    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }


}
